<?php if (!defined('BASEPATH')) exit('No direct script access allowed'); ?>

<?php 
	$ci = & get_instance();
	$tid = intval($_GET['tid']);
	
	$page = isset($_GET['per_page']) ? intval($_GET['per_page']) : 0 ;
	$records_per_page = 10; 
	$TOURNAMENT = $ci->tournament_entity->init("id", $tid);
	$match_array = $ci->match_entity->getMatchOfTournamentByStatus($tid, 'closed');
	
	$total = count($match_array);			
	$pagination = create_pagination( 
								$uri = 'cricket/contentload/closed_matches_of_tournament/?tid='.$tid, 
								$total_rows = $total , 
								$limit= $records_per_page,
								$uri_segment = 0,
								TRUE, TRUE 
							);
							
	$records = $ci->db->where("status LIKE 'closed' AND tournament_id='$tid'") 
			->order_by('end_time','desc')->limit($records_per_page, $page )->get(TBL_MATCH)->result();
	
	
?>

<div class="block">
	<div class="title"><span class="betticker" rel="div_closed_matches">&nbsp;</span><h3 class="bold">Closed Matches</h3></div>
	<div class="clrboth"></div>
	<div class="content" id="div_closed_matches">
	<?php foreach($records as $item): ?>
		<?php 
			$MATCH = $ci->match_entity->init('id', $item->id);
			$TEAM_HOME = clone_($ci->team_entity->init('id', $MATCH->getHome()));
			$TEAM_AWAY = clone_($ci->team_entity->init('id', $MATCH->getAway()));
		?>
	
		<div class="rowitem2">
			<div class="grid1">&nbsp;</div>
			<div class="grid6" style="text-align:center;"><h4><?php echo $MATCH->getTitle();?></h4></div>
			<div class="clrboth"></div>
			
			<div class="grid3">
				<div class="team">
					<?php echo thumb($TEAM_HOME->getMyFlagTeam(),IMG_TEAMPIC_W,IMG_TEAMPIC_H);?>
					<div class="clrboth"></div>
					<span class="bold">
						<?php echo $MATCH->displayMatchInfo('home');?>
					</span>
					<div class="clrboth"></div>
				</div>
			</div>
			 
			<div class="grid1" style="text-align:center;width:80px;"><?php echo vs_image(); ?></div> 
			 
			<div class="grid3">
				<div class="team">
					<?php echo thumb($TEAM_AWAY->getMyFlagTeam(),IMG_TEAMPIC_W,IMG_TEAMPIC_H);?>
					<div class="clrboth"></div>
					<span class="bold">
						<?php echo $MATCH->displayMatchInfo('away');?>
					</span>
					<div class="clrboth"></div>
				</div>
			</div>
			<div class="clrboth"></div>
			
			<div class="grid7">
				<div class="result-text" style="text-align:center;">
					<?php echo $MATCH->displayMatchInfo('closed');?>
					<div class="wrap-element">
						<a href='javascript:void(0);' onclick="return view_full_scorecard(<?php echo $MATCH->getId();?>);" >View Scorecard</a>
					</div>
				</div>
			</div>
			<div class="clrboth"></div>
		</div>
		<div class="clrboth"></div>
	<?php endforeach;?>	
		<div class="clear"></div>
		<div class="rowitem2">
			<div class="pagging" style="margin:10px 0px;" id="closedMatchesDivId">
				<div id="pagination_top_rank" style="float:right;padding-bottom:15px;">
					<?php echo $pagination['links'];?>
				</div>
			</div>	
		</div>	
		<div class="clear"></div>
	</div>
</div>	
